//---------------Sonic CD Horz Platform Script----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0	:	Object.OnObject
#alias Object.Value1	:	Object.Timer
#alias Object.Value2	:	Object.XVelocity
#alias Object.Value3	:	Object.OffSetXPos
#alias Object.Value4	:	Object.YVelocity
#alias Object.Value5	:	Object.Angle

// Property Values
#alias 0	:	START_MOVING_LEFT
#alias 1	:	START_MOVING_RIGHT

// Ink Effect Aliases
#alias 0 : INK_NONE   // Disables transparency
#alias 1 : INK_BLEND  // Uses half transparency
#alias 2 : INK_ALPHA  // Uses transparency value of Object.Alpha
#alias 3 : INK_ADD    // Uses transparency value of Object.Alpha, and a bright tint
#alias 4 : INK_SUB    // Uses transparency value of Object.Alpha, and a dark tint



sub ObjectMain
	Object.Angle   = Oscillation
	Object.Angle <<= 1

	if Object.PropertyValue == START_MOVING_RIGHT
		Object.Angle += 256
	end if
	
	Cos(Object.XVelocity, Object.Angle)
	Object.XVelocity *= 0x1800
	Object.XVelocity += Object.XPos
	Object.XVelocity &= 0xFFFF0000 // Truncate the value
	Object.XVelocity -= Object.OffSetXPos

	if Object.OnObject == true
		// Loss a bit of height when stepped
		if Object.Timer < 16
			Object.Timer++
			TempValue0  = Object.Timer
			TempValue0 &= 3
			if TempValue0 == 3
				Object.YVelocity = 0x10000
			else
				Object.YVelocity = 0
			end if
		else
			Object.YVelocity = 0
		end if
	else
		// Restore original YPos
		if Object.Timer > 0
			Object.Timer--
			TempValue0  = Object.Timer
			TempValue0 &= 3
			if TempValue0 == 3
				Object.YVelocity = -0x10000
			else
				Object.YVelocity = 0
			end if
		else
			Object.YVelocity = 0
		end if
	end if
	Object.OnObject = false
end sub


sub ObjectPlayerInteraction
	TempValue0  = Object.XPos
	Object.XPos = Object.OffSetXPos

	PlayerObjectCollision(C_PLATFORM, -32, -9, 32, 12)
	if CheckResult == true
		Object.OnObject = true
		Player.XPos += Object.XVelocity
		Player.YPos += Object.YVelocity
	end if

	Object.XPos = TempValue0
end sub


sub ObjectDraw
	Cos(Object.OffSetXPos, Object.Angle)
	Object.OffSetXPos *= 0x1800
	Object.OffSetXPos += Object.XPos
	Object.OffSetXPos &= 0xFFFF0000 // Truncate the value

	Object.YPos += Object.YVelocity
	DrawSpriteXY(0, Object.OffSetXPos, Object.YPos)
end sub


sub ObjectStartup
	LoadSpriteSheet("R4.5/Objects.gif")

	SpriteFrame(-32, -9, 64, 24, 60, 1)	// #0 - Platform
end sub


// ========================
// Editor Subs
// ========================

sub RSDKEdit
	if Editor.ReturnVariable == true
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			CheckResult  = Object.PropertyValue
			CheckResult &= 1
			break
		case 0 // type
			CheckResult  = Object.PropertyValue
			CheckResult &= 1
			break
		end switch
	else
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			Object.PropertyValue  = Editor.VariableValue
			Object.PropertyValue &= 1
			break
		case 0 // type
			Object.PropertyValue  = Editor.VariableValue
			Object.PropertyValue &= 1
			break
		end switch
	end if
end sub

sub RSDKDraw
	DrawSprite(0)

	if editor.showGizmos == true
		editor.drawingOverlay = true

			TempValue0 = Object.XPos
			TempValue0 -= 0x30 0000

			TempValue1 = Object.XPos
			TempValue1 += 0x30 0000

			Object.InkEffect  = INK_BLEND

			DrawSpriteFX(0, FX_INK, TempValue0, Object.YPos)
			DrawSpriteFX(0, FX_INK, TempValue1, Object.YPos)

			Object.InkEffect  = INK_NONE
			
			DrawLine(TempValue0, Object.YPos, TempValue1, Object.YPos, 0xFF, 0xFF, 0xFF)
			
			
		editor.drawingOverlay = false
	end if
end sub

sub RSDKLoad
	LoadSpriteSheet("R4.5/Objects.gif")
	SpriteFrame(-32, -9, 64, 24, 60, 1)	// #0 - Platform

	AddEditorVariable("startDir")
	SetActiveVariable("startDir")
	AddEnumVariable("Left", 0)
	AddEnumVariable("Right", 1)
end sub
